package com.qf.zyh.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.zyh.common.ResponseResult;
import com.qf.zyh.common.ResultType;
import com.qf.zyh.dao.RechargeMapper;
import com.qf.zyh.entity.Recharge;
import com.qf.zyh.services.RechargeServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RechargeServicesImpl implements RechargeServices {
    @Autowired
    private RechargeMapper rechargeMapper;

    @Override
    public ResultType table(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Recharge> list = rechargeMapper.selectAll();
        PageInfo info = new PageInfo(list);
        return new ResultType(0,"",(int)info.getTotal(),info.getList());
    }
    //删除
    @Override
    public ResponseResult delre(Integer[] ids) {
        rechargeMapper.delre(ids);
        return ResponseResult.getSuccess();
    }
    //添加
    @Override
    public ResponseResult addre(Recharge r) {
        int i = rechargeMapper.insertSelective(r);
        if (i>0) {
            return ResponseResult.getSuccess();
        }
        return ResponseResult.getFail("加错啦！");
    }
    //修改
    @Override
    public ResponseResult updatere(Recharge r) {
        int i = rechargeMapper.updateByPrimaryKeySelective(r);
        if (i>0) {
            return ResponseResult.getSuccess();
        }
        return ResponseResult.getFail("改错啦！");
    }
}
